package com.tj.bo.account.server.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.tj.bo.account.server.dao.OrderDepositDao;
import com.tj.bo.account.server.entity.OrderDepositEntity;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: account
 * Date: 2020-06-11
 * Time: 10:48:23.884
 */

@Repository
public class OrderDepositDaoImpl extends AbstractBaseMapper<OrderDepositEntity> implements OrderDepositDao {
    @Override
    public OrderDepositEntity selectLatestDepositOrder(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return getSqlSession().selectOne(getStatement("selectLatestDepositOrder"), params);
    }

    @Override
    public OrderDepositEntity selectDepositOrder(String depositOrderNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("depositOrderNo", depositOrderNo);
        return getSqlSession().selectOne(getStatement("selectDepositOrder"), params);
    }

    @Override
    public List<OrderDepositEntity> selectDepositOrdersByUserCode(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return getSqlSession().selectList(getStatement("selectDepositOrdersByUserCode"), params);
    }

    @Override
    public List<OrderDepositEntity> selectsDepositOrderListByStatusAndTime(Integer orderStatus, Date endTime) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderStatus", orderStatus);
        params.put("endTime", endTime);
        return getSqlSession().selectList(getStatement("selectsDepositOrderListByStatusAndTime"), params);
    }

    @Override
    public int updateDepositStatus(String orderNo, Integer status) {
        Map<String, Object> params = new HashMap<>();
        params.put("orderStatus", status);
        params.put("orderNo", orderNo);
        return getSqlSession().update(getStatement("updateDepositStatus"), params);
    }

    @Override
    public BigDecimal selectTotalDepositAmount(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return getSqlSession().selectOne(getStatement("selectTotalDepositAmount"), params);
    }
}